package br.com.reembolso.dao;

import java.security.NoSuchAlgorithmException;


import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import br.com.reembolso.encripty.Encripty;
import br.com.reembolso.entity.DadosBancarios;

public class DadosBancariosDAO extends DAO {

	private static DadosBancariosDAO instance;

	private DadosBancariosDAO() {
	}

	public static DadosBancariosDAO getInstance() {
		if (instance == null) {
			instance = new DadosBancariosDAO();
		}
		return instance;
	}

	public DadosBancarios autentica(DadosBancarios dadosBancarios)
			throws NoSuchAlgorithmException {
		HibernateUtility.beginTransaction();
		Criteria c = HibernateUtility.getSession().createCriteria(
				DadosBancarios.class);
		c.add(Restrictions.eq("email", dadosBancarios.getEmail().toLowerCase()));
		c.add(Restrictions.eq("senha",
				Encripty.criptografaSenha(dadosBancarios.getSenha())));
		HibernateUtility.commitTransaction();
		return (DadosBancarios) c.uniqueResult();
	}

}